// iisaccelerator - an iis isapi for upgrade web performance
//
// Copyright (C) 2006-2007 - BlueStone  (bluestn@163.com)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MD5CHECKSUM_H__B1A6B507_7823_11D7_AC54_00A1B0029840__INCLUDED_)
#define AFX_MD5CHECKSUM_H__B1A6B507_7823_11D7_AC54_00A1B0029840__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif

#include <windows.h>
#include <Wincrypt.h>

typedef 
BOOL (*LPMD5CHECKSUMCALLBACK)( LPVOID lpObj, int nCurBytes, int nTotalBytes );

class CMD5CheckSum  
{
public:
	CMD5CheckSum();
	virtual ~CMD5CheckSum();
	
	BOOL Initialize();

	BOOL ComputeFileHash(	LPCTSTR lpFileName, 
							BYTE *pbData, 
							int nSize, 
							LPVOID lpObj = NULL, 
							LPMD5CHECKSUMCALLBACK pCallBack = NULL,
							ULONG *plFileSize = NULL );
	
	int ComputeFileHash(	LPCTSTR lpFileName, 
							LPTSTR lpBuffer, 
							int nSize, 
							LPVOID lpObj = NULL, 
							LPMD5CHECKSUMCALLBACK pCallBack = NULL,
							ULONG *plFileSize = NULL );

	int ComputeHash(BYTE *pbData, int nSize, int nOffset = 0);
	int GetHashResult(BYTE *pbData, int nSize);
	int GetHashResult(LPTSTR lpBuffer, int nSize);

	int GetHashSize();

	DWORD GetLastError();
//	DWORD GetLastErrorMsg(LPTSTR lpBuffer, DWORD nSize);

protected:
	HCRYPTPROV m_hProv;				// CryptoProvider
	HCRYPTHASH m_hHash;				// Hash Handler
	
	DWORD m_dwLastError;			// Error No.
};


class CCodeCvt
{
public: 
	static LPTSTR Bin2Hex(const BYTE *pInBuf, int nLen, LPTSTR lpOutBuf, int nOutBufLen);
	static BYTE* Hex2Bin(LPCTSTR lpctIn, BYTE *pOut, int nOutBufLen);
};



#endif // !defined(AFX_MD5CHECKSUM_H__B1A6B507_7823_11D7_AC54_00A1B0029840__INCLUDED_)
